<%--
  Created by IntelliJ IDEA.
  User: 22179
  Date: 2025/3/5
  Time: 11:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/index_work.css">
    <title>Title</title>
    <script src="/static/css/jquery-3.3.1.js"></script>
    <style>
        table{
            border: 1px solid black;
            width: 800px;
            border-collapse: collapse;
            cellpadding:"0px" ;
            cellspacing:"0px";
        }
        table td, table th { /* 给所有的td和th加上边框 */
            border: 1px solid black;
            padding: 5px; /* 可以根据需要调整 */
        }
    </style>
    <script>
        var msg="${msg}";
        if(msg!=null && msg!=""){
            alert(msg);
            location.href="/User/inquire";
        }
    </script>
</head>
<body>
    <form action="/User/inquire" method="post">
        <%--<input value="/inquire" name="method" hidden>--%>
        账号:<input type="text" name="mname" id="mname" value="${mname}">
        年龄:<input type="text" name="mage"  id="mage" value="${mage}">
        性别:<input type="radio" name="msex" value="男" <c:if test="${msex=='男'}">checked</c:if>>男
            <input type="radio" name="msex" value="女" <c:if test="${msex=='女'}">checked</c:if>>女&nbsp;&nbsp;&nbsp;
        用户身份:<select name="mrid" id="rid">
        <option value="0">--请选择--</option>
        </select>
        <button>查询用户</button>
    </form>

        <button onclick="adduser()">添加用户</button>
        <table>
             <tr>
                <td>编号</td>
                <td>姓名</td>
                <td>账号</td>
                <td>密码</td>
                <td>年龄</td>
                <td>性别</td>
                <td>爱好</td>
                 <td>用户身份</td>
                 <td>角色</td>
                 <td>操作</td>
            </tr>
            <c:forEach items="${page.content}"  var="user" >
                <tr>
                    <td>${user.id}</td>
                    <td>${user.name}</td>
                    <td>${user.username}</td>
                    <td>${user.password}</td>
                    <td>${user.age}</td>
                    <td>${user.sex}</td>
                    <td>${user.hobby}</td>
                    <td>${user.rid}</td>
                    <td>${user.role.name}</td>
                    <td>
                        <button onclick="upuser(${user.id})">修改</button>
                        <button onclick="deuser(${user.id})">删除</button>
                    </td>
                </tr>
            </c:forEach>
        </table>
            <button onclick="show(1)">首页</button>
            <button onclick="le(${page.currentPage})">上一页</button>
            <button>第${page.currentPage}页/共${page.pageTotal}页</button>
            <button onclick="ri(${page.currentPage},${page.pageTotal})">下一页</button>
            <button onclick="show(${page.pageTotal})">尾页</button>
            共${page.recordTotal}条
    <script>
        var  rid = "${mrid}";
        var  mname = $("#mname").val();
        var  mage = $("#mage").val();
        var mrid;
        var msex=$("[name='msex']:checked").val();
        if( typeof (msex)=="undefined"){
            msex="";
        }

        //下拉框ajax
        $(function () {
                $.ajax({
                    //请求资源路径
                     url: "/User/getrole",
                    //异步请求
                    async: false,
                     //请求方式
                     type: "POST",
                    //响应数据形式  text  json
                     dataType: "json",
                    //请求成功后调用的回调函数
                     success: function (data) {
                         $("#rid").children().not(":eq(0)").remove();
                         for (var i = 0; i < data.length; i++) {
                            if(rid==data[i].id){
                                $("#rid").append("<option selected value=" + data[i].id + ">--" + data[i].name + "--</option>");
                            }else{
                                 $("#rid").append("<option value=" + data[i].id + ">--" + data[i].name + "--</option>");
                            }
                         }
                     }
                });

                mrid=$("#rid").val();

        });
        function ri(pagesize,pagetotal) {
            if(pagesize==pagetotal||typeof (pagesize)=="undefined"){
                alert("已经是最后一页了");
            }else{
                location.href="/User/inquire?pagesize="+(pagesize+1)+
                    "&mname="+mname+ "&mage="+mage+ "&msex="+msex+ "&mrid="+mrid;
            }
        }
        function  le(pagesize){
            if(pagesize==1||typeof (pagesize)=="undefined"){
                alert("已经是第一页了");
            }else{
                location.href="/User/inquire?pagesize="+(pagesize-1)+
                    "&mname="+mname+ "&mage="+mage+ "&msex="+msex+ "&mrid="+mrid;
            }
        }
        function show(pagesize){
            location.href="/User/inquire?pagesize="+pagesize+
                "&mname="+mname+ "&mage="+mage+ "&msex="+msex+ "&mrid="+mrid;

        }

        function deuser(id) {
            if(confirm("确定删除吗？")){
                location.href="/User/deuser?id="+id;
            }
        }
        function upuser(id) {
            location.href="/User/upuser?id="+id;
        }
        function adduser(){
            location.href="/User/getrole1";
        }

    </script>

</body>
</html>
